<script type="text/javascript" language="javascript">
	(function($)
		{
			/*whatever jQuery stuff*/
			$(function()
				{
					jQuery.validator.addMethod("detail_required", function(value, element, param)
						{
							var returnVal = true;
							if(CKEDITOR.instances.news_detail.getData()=='')
							{
								returnVal = false;
							}
							return returnVal;
						}, jQuery.validator.messages.detail_required);

					$("#Form").validate(
						{
							ignore: "",
							rules:
							{
								news_type_id: "required",
								news_subject: "required",
								news_brief: "required",
								news_detail:
								{
									detail_required:true
								},
								news_tag: "required"
							},
							showErrors: function(errorMap, errorList)
							{
								var messages='';
								for (var i = 0; i < errorList.length; i++)
								{
									messages += '- '+errorList[i].message+'\n';
								}
								if(messages) alert("<?php echo lang('requirement');?>: \n"+"¯¯¯¯¯¯¯¯¯¯ \n"+ messages);
								//this.defaultShowErrors();
							} ,
							submitHandler: function(e)
							{
								$('.ajax-loading',e).css('visibility','visible');
								if(queueSize > 0)
								{
									$('#file_upload').uploadifyUpload();
								} else
								{
									success_file = true;
								}
								var interval = setInterval(function()
									{
										if (success_file)
										{
											clearInterval(interval);
											//Send Form
											document.forms["Form"].submit();
										}
									}, 100);
							},
							onfocusout: false,
							onkeyup: false,
							onclick: false,
							messages:
							{
								news_type_id: "<?php echo lang('news_type');?>",
								news_subject: "<?php echo lang('news_subject');?>",
								news_brief: "<?php echo lang('news_brief');?>",
								news_detail:
								{
									detail_required: "<?php echo lang('news_detail');?>"
								},
								news_tag: "<?php echo lang('news_tag');?>",
							}
						});

					/*Images Upload*/
					var queueSize = 0;
					var imgname= new Array();
					var success_file = false;
					$('#file_upload').uploadify(
						{
                			'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                			'script'    : '<?php echo base_url();?>uploadify.php',
							'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
							'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                			'fileExt'   : '*.jpg;*.JPG;*.gif;*.GIF;*.png;*.PNG',
							'fileDesc'  : 'All Files',
							'scriptAccess' : 'always',
							'auto'      : false,
							'multi'     : true,
							'onComplete' : function(event, ID, fileObj, response, data)
							{
								imgname.push(response);
							},
							'onAllComplete' : function(event,data)
							{
								$('<input>').attr(
									{
										type: 'hidden',
										id: 'uploadify_store',
										name: 'uploadify_store',
										value: imgname
									}).appendTo('Form');
								//document.forms["Form"].submit();
								success_file=true;
							},
							'onSelectOnce' : function (event,data)
							{
								queueSize = data.fileCount;
							},
							'onCancel' : function (event,ID,fileObj,data)
							{
								queueSize = data.fileCount;
							}
						});
					//DateTime Picker
					$('.datetime').datetimepicker({
						dateFormat:'dd/mm/yy',
						timeFormat:'hh:mm',
						separator:' ',
			            changeMonth : true,
			            changeYear : true,
			            yearRange: '-100y:c+nn',
			            maxDate: '-1d',
						showHour: true,		
						showMinute: true,
						showTime: true		
					});	
					//ColorBox Iframe
					$('.search_tools').colorbox({onLoad:function(){ news_relate_on_search = ''; },iframe:true, innerWidth:300, innerHeight:600, right:0, opacity:0.4});
					//ColorBox Image
					$('a[rel="gallery"]').colorbox();
					//Drag && Drop
					$( ".listImages" ).sortable(
						{
							connectWith: "li",
							cursor: 'move',
							handle: 'img',
							placeholder: 'placeholder',
							forcePlaceholderSize: true,
							opacity: 0.4,
							update: function(event, ui)
							{
								//do process
								var data = $(this).sortable('serialize');
								$.ajax(
									{
										type:'post',
										url:web_path+'news/content_management/ajax_update_image',
										data:data
									});
							}
						}).disableSelection();
				});
		})(jQuery);
		/*Show Search*/
		var news_relate_on_search=''
		function showSearch(e)
		{
			$(e).parent().find('.search_tools2').remove();
			$(e).parent().find('input').val('');
			switch(e.value){
				case 'Album':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_album";?>" class="tools magnify search_tools2"></a>');
				break;
				case 'Movie':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_movie";?>" class="tools magnify search_tools2"></a>');
				break;
				case 'Song':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_song";?>" class="tools magnify search_tools2"></a>');
				break;
				case 'Video':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_video";?>" class="tools magnify search_tools2"></a>');
				break;
				case 'Gallery':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_gallery";?>" class="tools magnify search_tools2"></a>');
				break;
				case 'Fashion':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_fashion";?>" class="tools magnify search_tools2"></a>');
				break;																				
			}
			$('.search_tools2').colorbox({
				onLoad:function(){ news_relate_on_search = $(this).parent(); },
				onClosed:function(){ news_relate_on_search = "";},
				iframe:true, 
				innerWidth:300, 
				innerHeight:600, 
				right:0, 
				opacity:0.4
			});
		}
		/*Add/Remove List*/
		function addRemoveList(unique,id,name)
		{
			if(news_relate_on_search != ""){
				news_relate_on_search.find('input[name="news_relate_id[]"]').val(''+id+'');	
			} else {
				if(id == undefined && name == undefined){ //remove List
					var parentElement = $(unique).closest('ul');
					$(unique).parent().remove();
					if($('li:not(:hidden)',parentElement).length < 1){
						parentElement.find('.first').show();
					}	
				} else { //add List
					var parentElement = $('#'+unique).closest('ul');
					parentElement.find('.first').hide();
					if($('input[value="'+id+'"]',parentElement).length == 0){
						parentElement.prepend('<li><input type="checkbox" name="default_'+unique+'[]" checked="checked"/>&nbsp;'+id+' - '+name+' <a href="javascript:void(0)" class="tools minus" onclick="javascript:addRemoveList(this);"></a><input type="hidden" name="'+unique+'[]" value="'+id+'" \/><\/li>');
					}		
				}				
			}
		}		
</script>
<div class="wrap">
	<div id="icon-index" class="icon32">
		<br />
	</div>
	<h2>
		<?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?> &raquo; <?php echo lang($this->uri->segment(3));?>
	</h2>
</div>
<div id="wpbody-content">
	<div class="metabox-holder" id="dashboard-widgets">
		<div class="tablenav top">
			<div class="alignleft">
				<input type="button" value="<?php echo lang('button_back');?>" class="button-primary" onclick="javascript:history.go(-1);"/>
			</div>
		</div>
		<div class="inside">
			<form id="Form" method="post" action="" name="Form">
				<table border="0" cellspacing="0" cellpadding="0" class="form-table">
					<tbody>
						<tr>
							<th scope="row">
								<?php echo lang('is_publish');?>
							</th>
							<td>
								<input type="radio" name="is_publish" value="1" <?php echo ($dataResult->is_publish == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_publish" value="0" <?php echo ($dataResult->is_publish == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row">
								<?php echo lang('news_publish_date');?>
							</th>
							<td>
								<input type="text" name="news_publish_date" id="news_publish_date" class="medium-text datetime" value="<?php echo convertDatetimeToString($dataResult->news_publish_date);?>" readonly="readonly"/>
							</td>
						</tr>						
						<tr>
							<th scope="row">
								<?php echo lang('news_type');?>
							</th>
							<td>
								<select id="news_type_id" name="news_type_id" class="medium-text" onchange="javacript:if($('.news_type_id_'+this.value+'').length > 0){$('tr[class*=\'news_type_id_\']').hide();$('.news_type_id_'+this.value+'').show()} else {$('tr[class*=\'news_type_id_\']').hide();}">
									<option value="">
										<?php echo lang('select_option');?>
									</option>
									<?php
									foreach($dataNewsType as $value):?>
									<option value="<?php echo $value->news_type_id;?>" <?php echo ($value->news_type_id == $dataResult->news_type_id ? 'selected="selected"':'');?>>
										<?php echo $value->news_type_name;?>
									</option>
									<?php endforeach;?>
								</select>					
							</td>
						</tr>
						<tr class="news_type_id_5" <?php echo ($dataResult->news_type_id == 5 ? '':'style="display:none;"');?>>
							<th scope="row">
								<?php echo lang('news_review_hilight');?>
							</th>
							<td>
								<input type="radio" name="is_review_hilight" value="1" <?php echo ($dataResult->is_review_hilight == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_review_hilight" value="0" <?php echo ($dataResult->is_review_hilight == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>										
						<tr>
							<th scope="row">
								<?php echo lang('news_main_hilight');?>
							</th>
							<td>
								<input type="radio" name="is_main_hilight" value="1" <?php echo ($dataResult->is_main_hilight == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_main_hilight" value="0" <?php echo ($dataResult->is_main_hilight == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row">
								<?php echo lang('news_type_hilight');?>
							</th>
							<td>
								<input type="radio" name="is_type_hilight" value="1" <?php echo ($dataResult->is_type_hilight == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_type_hilight" value="0" <?php echo ($dataResult->is_type_hilight == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('author_by');?></th>
							<td>
								<select name="author_by" id="author_by">
									<option <?php echo ($dataResult->author_by == "YOU2PLAY" ? 'selected="selected"':'');?>>YOU2PLAY</option>
									<option <?php echo ($dataResult->author_by == "หัตถาครองพิภพ" ? 'selected="selected"':'');?>>หัตถาครองพิภพ</option>
									<option <?php echo ($dataResult->author_by == "นักเลงเพลงสยาม" ? 'selected="selected"':'');?>>นักเลงเพลงสยาม</option>
								</select>
							</td>
						</tr>											
						<tr>
							<th scope="row">
								<?php echo lang('news_subject');?>
							</th>
							<td>
								<input type="text" name="news_subject" id="news_subject" class="regular-text" value="<?php echo htmlspecialchars($dataResult->news_subject, ENT_QUOTES, 'UTF-8');?>"/>
							</td>
						</tr>
						<tr>
							<th scope="row">
								<?php echo lang('news_brief');?>
							</th>
							<td>
								<textarea name="news_brief" id="news_brief" rows="5" class="regular-text"><?php echo $dataResult->news_brief;?></textarea>
							</td>
						</tr>
						<tr>
							<th scope="row">
								<?php echo lang('news_detail');?>
							</th>
							<td>
								<?php echo display_ckeditor('news_detail',''.$dataResult->news_detail.'',array('toolbar'=> 'Medium','skin'   => 'v2','width'  => '550px','height' => '200px'),false); ?>
							</td>
						</tr>
						<tr>
							<th scope="row">
								<?php echo lang('news_tag');?>
							</th>
							<td>
								<input type="text" name="news_tag" id="news_tag" class="regular-text" value="<?php echo htmlspecialchars($dataResult->news_tag, ENT_QUOTES, 'UTF-8');?>"/>
							</td>
						</tr>
						<tr>
							<th scope="row">
								<?php echo lang('artist_relate');?>
								<a href="<?php echo base_url().'news/content_management/search_artist';?>" class="tools plus search_tools">
								</a>
							</th>
							<td class="describe">
								<ul id="artist_id" class="listItems">
									<?php
									if(!empty($dataNewsArtist)):?>
									<li class="first" style="display:none;">
										<?php echo lang('no_artist_relate');?>
									</li>
									<?php
									foreach($dataNewsArtist as $value):?>
									<li>
										<input type="checkbox" name="default_artist_id[]" checked="checked" disabled="disabled"/>
										<?php echo $value->artist_id.' - '.$value->artist_name;?>
										<a
											href="javascript:void(0)" class="tools minus" onclick="javascript:addRemoveList(this);">
										</a><input type="hidden" name="artist_id[]" value="<?php echo $value->artist_id;?>" />
									</li>
									<?php endforeach;?>
									<?php
									else:?>
									<li class="first">
										<?php echo lang('no_artist_relate');?>
									</li>
									<?php endif;?>
								</ul>
							</td>
						</tr>						
						<tr>
							<th scope="row">
								<?php echo lang('news_image');?>
							</th>
							<td>
								<?php
								if(!empty($dataNewsImage)):?>
								<ul class="listImages">
									<?php
									foreach($dataNewsImage as $value):?>
									<li id="news_image_id_<?php echo $value->news_image_id;?>">
										<div>
											<a href="<?php echo image_asset_url('../uploads/news/images/original/'.$value->news_file_name.'.'.$value->news_file_ext);?>" rel="gallery">
												<?php echo image_asset('../uploads/news/images/120x120/'.$value->news_file_name.'.'.$value->news_file_ext,'',array('width' => 120,'height'=> 120));?>
											</a>
										</div>
										<a href="javascript:void(0);" title="<?php echo image_asset_url('../uploads/news/images/original/'.$value->news_file_name.'.'.$value->news_file_ext);?>" onmouseOver="javascript:toClipboard(this)" class="tools wishlist"></a>
										<a href="<?php echo base_url();?>news/content_management/ajax_delete_image/<?php echo $value->news_image_id;?>" class="tools delete deleteImage"></a>
									</li>
									<?php endforeach;?>
								</ul>
								<?php endif;?>
								<input type="file" name="file_upload" id="file_upload"/>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('news_relate');?></th>
							<td>
								<a href="javascript:void(0);" class="tools minus" onclick="javascript:removeclone(this,'div');"></a>
								<a href="javascript:void(0);" class="tools plus" onclick="javascript:addclone(this,'div');"></a>
								<?php $news_relate = json_decode($dataResult->news_relate);?>
								<?php if(!empty($news_relate)):?>
									<?php foreach($news_relate as $key => $value):?>
										<div style="padding:3px 0;">
											<select name="news_relate_module[]" onchange="javascript:showSearch(this);">
												<option value=""><?php echo lang('select_option');?></option>
												<option value="Album" <?php echo ($value->module == "Album" ? 'selected="selected"':'');?>>Album ID:</option>								
												<option value="Movie" <?php echo ($value->module == "Movie" ? 'selected="selected"':'');?>>Movie ID:</option>
												<option value="Song" <?php echo ($value->module == "Song" ? 'selected="selected"':'');?>>Song ID:</option>
												<option value="Video" <?php echo ($value->module == "Video" ? 'selected="selected"':'');?>>Video ID:</option>
												<option value="Gallery" <?php echo ($value->module == "Gallery" ? 'selected="selected"':'');?>>Gallery ID:</option>
												<option value="Fashion" <?php echo ($value->module == "Fashion" ? 'selected="selected"':'');?>>Fashion ID:</option>
											</select>
											<input type="text" name="news_relate_id[]" class="small-text" value="<?php echo $value->value;?>"/>
										</div>
									<?php endforeach;?>
								<?php else:?>
								<div style="padding:3px 0;">
									<select name="news_relate_module[]" onchange="javascript:showSearch(this);">
										<option value=""><?php echo lang('select_option');?></option>
										<option value="Album">Album ID:</option>
										<option value="Movie">Movie ID:</option>
										<option value="Song">Song ID:</option>
										<option value="Video">Video ID:</option>
										<option value="Gallery">Gallery ID:</option>
										<option value="Fashion">Fashion ID:</option>
									</select>
									<input type="text" name="news_relate_id[]" class="small-text" readonly="readonly"/>
								</div>
								<?php endif;?>
							</td>
						</tr>						
						<tr>
							<th scope="row">
								<?php echo lang('update_date');?>
							</th>
							<td class="describe"><?php echo $dataResult->update_date;?></td>
						</tr>						
						<tr>
							<th scope="row">
								&nbsp;
							</th>
							<td>
								<p class="submit">
									<input type="submit" value="<?php echo lang('button_edit');?>" class="button-primary" />&nbsp;<img alt="" class="ajax-loading" src="<?php echo css_asset_url('images/wpspin_light.gif'); ?>" />
								</p>
							</td>
						</tr>
					</tbody>
				</table>
				<div class="tablenav bottom">
				</div>
			</form>
		</div><!-- wpbody inside -->
	</div><!-- wpcontent -->
</div><!-- wpbody-content -->